module Roled
  module Core
    extend ActiveSupport::Concern
    
    included do
    end
    
    def authorize_user!(user, options = {})
      if defined?(options[:skip_module])
        if params[:controller] =~ /#{options[:skip_module]}\/\.*/
          return
        end
      end
      if(!user.blank?)
        action = params[:action]
        if(!action)
          action = "index"
        end
        request = user.has_permission_to? params[:controller], action
        if(request != nil && request)
        else
          redirect_to root_url, :flash => {:error => "Unauthorized"}
        end
      end
    end
    
  end
end